package com.moyun.controller.system;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.moyun.common.annotation.OperLog;
import com.moyun.common.aspect.BusinessType;
import com.moyun.controller.common.CommonController;
import com.moyun.model.common.R;
import com.moyun.common.cache.dict.DictDataCache;
import com.moyun.model.vo.system.DictItemOptions;
import com.moyun.model.vo.system.DictTypeOptions;
import com.moyun.model.po.dict.SysDict;
import com.moyun.service.dict.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author yangbx
 * @since 2022-06-18
 */
@Api(tags = "字典类型")
@RestController
@RequestMapping("/dict/sysDict")
@RequiredArgsConstructor
public class SysDictController  {
    private final SysDictService sysDictService;

    @ApiOperation("添加数据(增)")
    @ApiOperationSupport(order = 1)
    @OperLog(operModul = "", operType = BusinessType.INSERT, operDesc = "")
    @PostMapping("save")
    public R save(@RequestBody @Validated SysDict entity) {
        boolean isSave = this.sysDictService.save(entity);
        return isSave ? R.ok(0, "操作成功") : R.error(1, "操作失败");
    }

    @GetMapping("type/options")
    @ApiOperation(value = "获取字典类型下拉选项")
    public R<Set<DictTypeOptions>> selectOptions() {
        Set<DictTypeOptions> typeList = DictDataCache.getTypeList();
        return R.ok(typeList);
    }

    @GetMapping("data/options/{typeCode}")
    @ApiOperation(value = "获取字典数据下拉选项")
    public R<List<DictItemOptions>> selectDataOptions(@PathVariable String typeCode) {
        List<DictItemOptions> dictItemOptions = DictDataCache.get(typeCode);
        return R.ok(dictItemOptions);
    }
    @GetMapping("data/options/{loadType}/{typeCode}")
    @ApiOperation(value = "获取字典数据下拉选项，可以根据加载参数，找找不同的数据")
    public R<List<DictItemOptions>> selectDataOptionsByLoadType(@PathVariable String loadType, @PathVariable String typeCode) {
        return null;
    }

}

